package com.graduation.sports.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.graduation.sports.R;
import com.graduation.sports.bean.DailyExerciseInfo;
import com.graduation.sports.bean.GroupInfo;
import com.graduation.sports.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

public class DailyTrainAdapter extends RecyclerView.Adapter<DailyTrainAdapter.DailyTrainViewHolder>{
    private Context mContext;
    private List<DailyExerciseInfo> mListData = new ArrayList<>();

    public DailyTrainAdapter(Context mContext, List<DailyExerciseInfo> mListData) {
        //  mListData = new ArrayList<>();
        this.mContext = mContext;
        this.mListData = mListData;
    }

    public void update(List<DailyExerciseInfo> list){
        if(list != null && list.size() > 0){
            mListData = list;
            notifyDataSetChanged();
        }
    }

    @NonNull
    @Override
    public DailyTrainViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if(mContext == null){
            mContext = parent.getContext();
        }
        View view  = LayoutInflater.from(mContext).inflate(R.layout.layout_item_daily_train,parent,false);
        return new DailyTrainViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull DailyTrainViewHolder holder, int position) {
        DailyExerciseInfo dailyExerciseInfo = mListData.get(position);
        if (dailyExerciseInfo == null) {
            return;
        }
        holder.trainName.setText(dailyExerciseInfo.getSportName());
        holder.trainTime.setText(dailyExerciseInfo.getExerciseTime());

        if (dailyExerciseInfo.getSportName() == "跑步") {
            holder.labelContent.setText("总公里数：");
            holder.trainContent.setText(dailyExerciseInfo.getmDistance() + "m");
        } else {
            holder.labelContent.setText("总次数：");
            holder.trainContent.setText(dailyExerciseInfo.getTimes() + "");
        }

    }

    @Override
    public int getItemCount() {
        return  mListData.isEmpty() ? 0 : mListData.size();
    }

    class DailyTrainViewHolder extends RecyclerView.ViewHolder{
        TextView trainName;
        TextView trainTime;
        TextView trainContent;
        TextView labelContent;
        public DailyTrainViewHolder(@NonNull View itemView) {
            super(itemView);
            trainName =  itemView.findViewById(R.id.item_train_name);
            trainTime =  itemView.findViewById(R.id.item_train_time);
            trainContent =  itemView.findViewById(R.id.item_train_content);
            labelContent =  itemView.findViewById(R.id.label_content);
        }
    }
}
